﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;

namespace myBoard.Framework.Package
{
    public class PackagedFolder
    {
        private ObservableCollection<PackagedFile> _files;
        private ObservableCollection<PackagedFolder> _folders;
        private DirectoryInfo _directoryInfo;
        private MemoryStream _packagedFolderMemoryStream;

        public MemoryStream PackagedFolderMemoryStream
        {
            get { return _packagedFolderMemoryStream; }
        }

        public void Pack(string folderPath)
        {
            if (!Directory.Exists(folderPath))
                throw new DirectoryNotFoundException(string.Format("Specified folder does not exist : {0}", folderPath));
            /*
            _files = new ObservableCollection<PackagedFile>();
            _directoryInfo = new DirectoryInfo(folderPath);
            FileInfo[] files = _directoryInfo.GetFiles();
            foreach (FileInfo fi in files)
            {
                _files.Add(new PackagedFile());
            }

            int totalFilesSize=0;
            foreach (PackagedFile file in _files)
            {
                file.Pack();
                totalFilesSize += Convert.ToInt32(file.PackagedFileStream.Length);
            }
            byte[] buffer = new byte[totalFilesSize];
            MemoryStream ms = new MemoryStream(buffer, 0, buffer.Length, true, true);
            foreach (PackagedFile file in _files)
            {
                byte[] b = file.PackagedFileStream.GetBuffer();
                ms.Write(b, 0, b.Length);
            }
            FileStream fs = new FileStream(@"c:\titi.txt", FileMode.Create);
            fs.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            ms.Dispose();
            fs.Dispose();*/
        }

        public void UnPack(string fileToUnpack)
        {
            if (!File.Exists(fileToUnpack))
                throw new FileNotFoundException(string.Format("Specified file does not exist : {0}.",fileToUnpack));
            StreamReader sr = new StreamReader(fileToUnpack);
            

        }
    }
}
